<html>
<head><meta charset="utf-8"><title>Is this example safe? · t-lang/wg-unsafe-code-guidelines · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/index.html">t-lang/wg-unsafe-code-guidelines</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Is.20this.20example.20safe.3F.html">Is this example safe?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="207492333"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Is%20this%20example%20safe%3F/near/207492333" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Is.20this.20example.20safe.3F.html#207492333">(Aug 20 2020 at 06:24)</a>:</h4>
<p>This is an example from the pointer documentation:</p>
<div class="codehilite"><pre><span></span><code><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">s</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">[</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="p">];</span><span class="w"></span>
<span class="kd">let</span><span class="w"> </span><span class="n">ptr</span>: <span class="o">*</span><span class="k">mut</span><span class="w"> </span><span class="kt">u32</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">s</span><span class="p">.</span><span class="n">as_mut_ptr</span><span class="p">();</span><span class="w"></span>
<span class="kd">let</span><span class="w"> </span><span class="n">first_value</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">unsafe</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">ptr</span><span class="p">.</span><span class="n">as_mut</span><span class="p">().</span><span class="n">unwrap</span><span class="p">()</span><span class="w"> </span><span class="p">};</span><span class="w"></span>
<span class="o">*</span><span class="n">first_value</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">4</span><span class="p">;</span><span class="w"></span>
<span class="n">println</span><span class="o">!</span><span class="p">(</span><span class="s">&quot;{:?}&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">s</span><span class="p">);</span><span class="w"> </span><span class="c1">// It&#39;ll print: &quot;[4, 2, 3]&quot;.</span>
</code></pre></div>


<p>It seems like this should be UB because <code>first_value</code> is a mutable reference that is live at the same time as <code>s</code>. Can't the compiler reason that <code>s</code> is still <code>[1,2,3]</code> because it was still <code>[1,2,3]</code> as of the end of line 2, and no mutable references derived from <code>s</code> were created in the meantime (since the pointer doesn't count).</p>



<a name="207492531"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Is%20this%20example%20safe%3F/near/207492531" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Is.20this.20example.20safe.3F.html#207492531">(Aug 20 2020 at 06:29)</a>:</h4>
<p>I think this example is sound, you can test this using MIRI.</p>
<p>pointers do count, they "just" aren't tracked. So as long as you don't use a reference which was created before the pointer you can use pointers however you want</p>



<a name="207492639"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Is%20this%20example%20safe%3F/near/207492639" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Is.20this.20example.20safe.3F.html#207492639">(Aug 20 2020 at 06:31)</a>:</h4>
<p>It would be UB if you mutate <code>s[0]</code> after creating <code>ptr</code></p>
<div class="codehilite"><pre><span></span><code><span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">s</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">[</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="p">];</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">ptr</span>: <span class="o">*</span><span class="k">mut</span><span class="w"> </span><span class="kt">u32</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">s</span><span class="p">.</span><span class="n">as_mut_ptr</span><span class="p">();</span><span class="w"></span>
<span class="w">    </span><span class="n">s</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">3</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">first_value</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">unsafe</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">ptr</span><span class="p">.</span><span class="n">as_mut</span><span class="p">().</span><span class="n">unwrap</span><span class="p">()</span><span class="w"> </span><span class="p">};</span><span class="w"></span>
<span class="w">    </span><span class="o">*</span><span class="n">first_value</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">4</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="n">println</span><span class="o">!</span><span class="p">(</span><span class="s">&quot;{:?}&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">s</span><span class="p">);</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="207492743"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Is%20this%20example%20safe%3F/near/207492743" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Is.20this.20example.20safe.3F.html#207492743">(Aug 20 2020 at 06:33)</a>:</h4>
<p>I thought it was illegal to even have two unique pointers to the same allocation, even if you don't use them</p>



<a name="207492950"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Is%20this%20example%20safe%3F/near/207492950" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Is.20this.20example.20safe.3F.html#207492950">(Aug 20 2020 at 06:36)</a>:</h4>
<p>you can have infinitely many pointer to the same allocation</p>



<a name="207492976"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Is%20this%20example%20safe%3F/near/207492976" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Is.20this.20example.20safe.3F.html#207492976">(Aug 20 2020 at 06:37)</a>:</h4>
<p>sorry, I meant reference not pointer</p>



<a name="207492984"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Is%20this%20example%20safe%3F/near/207492984" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Is.20this.20example.20safe.3F.html#207492984">(Aug 20 2020 at 06:37)</a>:</h4>
<p>creating  a new mutable reference makes using a previous mutable reference UB</p>



<a name="207493056"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Is%20this%20example%20safe%3F/near/207493056" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Is.20this.20example.20safe.3F.html#207493056">(Aug 20 2020 at 06:38)</a>:</h4>
<p>so this use is okay because it is the same as</p>
<div class="codehilite"><pre><span></span><code><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">s</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">[</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="p">];</span><span class="w"></span>
<span class="kd">let</span><span class="w"> </span><span class="n">first_value</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;</span><span class="k">mut</span><span class="w"> </span><span class="n">s</span><span class="p">[</span><span class="mi">0</span><span class="p">];</span><span class="w"></span>
<span class="o">*</span><span class="n">first_value</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">4</span><span class="p">;</span><span class="w"></span>
<span class="n">println</span><span class="o">!</span><span class="p">(</span><span class="s">&quot;{:?}&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">s</span><span class="p">);</span><span class="w"> </span><span class="c1">// It&#39;ll print: &quot;[4, 2, 3]&quot;.</span>
</code></pre></div>



<a name="207493083"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Is%20this%20example%20safe%3F/near/207493083" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Is.20this.20example.20safe.3F.html#207493083">(Aug 20 2020 at 06:39)</a>:</h4>
<p>so <code>s</code> is supposed to be considered borrowed while <code>ptr</code> / <code>first_value</code> are active</p>



<a name="207493093"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Is%20this%20example%20safe%3F/near/207493093" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Is.20this.20example.20safe.3F.html#207493093">(Aug 20 2020 at 06:39)</a>:</h4>
<p>even if the type system doesn't know</p>



<a name="207493101"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Is%20this%20example%20safe%3F/near/207493101" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Is.20this.20example.20safe.3F.html#207493101">(Aug 20 2020 at 06:39)</a>:</h4>
<p>yeah, stacked borrows works outside of the type system</p>



<a name="207493113"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Is%20this%20example%20safe%3F/near/207493113" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Is.20this.20example.20safe.3F.html#207493113">(Aug 20 2020 at 06:40)</a>:</h4>
<p>have you read <a href="https://www.ralfj.de/blog/2018/08/07/stacked-borrows.html">https://www.ralfj.de/blog/2018/08/07/stacked-borrows.html</a> ?</p>



<a name="207493171"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Is%20this%20example%20safe%3F/near/207493171" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Is.20this.20example.20safe.3F.html#207493171">(Aug 20 2020 at 06:40)</a>:</h4>
<p>I've read the paper too</p>



<a name="207493187"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Is%20this%20example%20safe%3F/near/207493187" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Is.20this.20example.20safe.3F.html#207493187">(Aug 20 2020 at 06:40)</a>:</h4>
<p>I get that it's a semantic ("runtime") version of the borrow checker</p>



<a name="207493230"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Is%20this%20example%20safe%3F/near/207493230" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Is.20this.20example.20safe.3F.html#207493230">(Aug 20 2020 at 06:41)</a>:</h4>
<p>but my recollection was that even creating aliasing <code>&amp;mut</code>'s is UB territory</p>



<a name="207493277"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Is%20this%20example%20safe%3F/near/207493277" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Is.20this.20example.20safe.3F.html#207493277">(Aug 20 2020 at 06:42)</a>:</h4>
<p>If you pass <code>s</code> and <code>first_value</code> to a function accepting two <code>&amp;mut</code>'s that would be UB, yes?</p>



<a name="207493283"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Is%20this%20example%20safe%3F/near/207493283" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Is.20this.20example.20safe.3F.html#207493283">(Aug 20 2020 at 06:42)</a>:</h4>
<p>even if <code>f</code> doesn't do anything with them</p>



<a name="207493286"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Is%20this%20example%20safe%3F/near/207493286" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Is.20this.20example.20safe.3F.html#207493286">(Aug 20 2020 at 06:42)</a>:</h4>
<p><span class="user-mention silent" data-user-id="271719">Mario Carneiro</span> <a href="#narrow/stream/136281-t-lang.2Fwg-unsafe-code-guidelines/topic/Is.20this.20example.20safe.3F/near/207493277">said</a>:</p>
<blockquote>
<p>If you pass <code>s</code> and <code>first_value</code> to a function accepting two <code>&amp;mut</code>'s that would be UB, yes?</p>
</blockquote>
<p>yeah, mutable references passed to functions are considered used afaik</p>



<a name="207493303"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Is%20this%20example%20safe%3F/near/207493303" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Is.20this.20example.20safe.3F.html#207493303">(Aug 20 2020 at 06:43)</a>:</h4>
<p>iirc because we explicitly retag them at the start</p>



<a name="207493358"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Is%20this%20example%20safe%3F/near/207493358" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Is.20this.20example.20safe.3F.html#207493358">(Aug 20 2020 at 06:44)</a>:</h4>
<p>aha, yes I see that now in the <code>demo4</code> example of the blog post</p>



<a name="207493450"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Is%20this%20example%20safe%3F/near/207493450" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Is.20this.20example.20safe.3F.html#207493450">(Aug 20 2020 at 06:46)</a>:</h4>
<p>what is the currently authoritative version of stacked borrows? Is it the code in miri or the coq formalization?</p>



<a name="207493463"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Is%20this%20example%20safe%3F/near/207493463" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Is.20this.20example.20safe.3F.html#207493463">(Aug 20 2020 at 06:46)</a>:</h4>
<p>tbh I don't even think that there exists one</p>



<a name="207493473"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Is%20this%20example%20safe%3F/near/207493473" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Is.20this.20example.20safe.3F.html#207493473">(Aug 20 2020 at 06:47)</a>:</h4>
<p>lol we need a specification for the specification</p>



<a name="207493480"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Is%20this%20example%20safe%3F/near/207493480" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Is.20this.20example.20safe.3F.html#207493480">(Aug 20 2020 at 06:47)</a>:</h4>
<p>considering that we never had an official lang team decision on this (and we probably don't want to for now if we want to ever make this more strict)</p>



<a name="207493495"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Is%20this%20example%20safe%3F/near/207493495" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Is.20this.20example.20safe.3F.html#207493495">(Aug 20 2020 at 06:47)</a>:</h4>
<p>so I guess the "best" version is the current implementation in miri itself</p>



<a name="207721319"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Is%20this%20example%20safe%3F/near/207721319" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Is.20this.20example.20safe.3F.html#207721319">(Aug 22 2020 at 12:02)</a>:</h4>
<p><span class="user-mention silent" data-user-id="271719">Mario Carneiro</span> <a href="#narrow/stream/136281-t-lang.2Fwg-unsafe-code-guidelines/topic/Is.20this.20example.20safe.3F/near/207493450">said</a>:</p>
<blockquote>
<p>what is the currently authoritative version of stacked borrows? Is it the code in miri or the coq formalization?</p>
</blockquote>
<p>both should actually be in sync currently</p>



<a name="207721343"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Is%20this%20example%20safe%3F/near/207721343" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Is.20this.20example.20safe.3F.html#207721343">(Aug 22 2020 at 12:03)</a>:</h4>
<p>the coq formalization exists at <a href="https://gitlab.mpi-sws.org/FP/stacked-borrows/">https://gitlab.mpi-sws.org/FP/stacked-borrows/</a></p>



<a name="207721346"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Is%20this%20example%20safe%3F/near/207721346" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/Is.20this.20example.20safe.3F.html#207721346">(Aug 22 2020 at 12:03)</a>:</h4>
<p><span class="user-mention silent" data-user-id="271719">Mario Carneiro</span> <a href="#narrow/stream/136281-t-lang.2Fwg-unsafe-code-guidelines/topic/Is.20this.20example.20safe.3F/near/207493083">said</a>:</p>
<blockquote>
<p>so <code>s</code> is supposed to be considered borrowed while <code>ptr</code> / <code>first_value</code> are active</p>
</blockquote>
<p>yes, exactly!</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>